﻿using System;
using System.Data;
using System.Text;
using System.Data.OleDb;
using Maticsoft.DBUtility;
namespace KF.DHL.DAL
{
    public partial class AdditionalChargeDAL
    {
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(KF.DHLModel.AdditionalCharge model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into AdditionalCharge (");
            strSql.Append("[BillDate],[BillAmount],[AddWho],[CustomerCode],[OrderNumber],[RefOrderNumber],[Amount],[Notes],[AddTime],[Status],[BillWho]");
            strSql.Append(") values (");
            strSql.Append("@BillDate,@BillAmount,@AddWho,@CustomerCode,@OrderNumber,@RefOrderNumber,@Amount,@Notes,@AddTime,@Status,@BillWho");
            strSql.Append(") ");
            //strSql.Append(";select @@IDENTITY");
            OleDbParameter[] parameters = {
			            new OleDbParameter("@BillDate", OleDbType.Date) ,            
                        new OleDbParameter("@BillAmount", OleDbType.Date) ,            
                        new OleDbParameter("@AddWho", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@CustomerCode", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@OrderNumber", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@RefOrderNumber", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@Amount", OleDbType.Double) ,            
                        new OleDbParameter("@Notes", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@AddTime", OleDbType.Date) ,            
                        new OleDbParameter("@Status", OleDbType.Integer,4) ,            
                        new OleDbParameter("@BillWho", OleDbType.VarChar,255)             
              
            };

            parameters[0].Value = model.BillDate;
            parameters[1].Value = model.BillAmount;
            parameters[2].Value = model.AddWho;
            parameters[3].Value = model.CustomerCode;
            parameters[4].Value = model.OrderNumber;
            parameters[5].Value = model.RefOrderNumber;
            parameters[6].Value = model.Amount;
            parameters[7].Value = model.Notes;
            parameters[8].Value = model.AddTime;
            parameters[9].Value = model.Status;
            parameters[10].Value = model.BillWho;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(KF.DHLModel.AdditionalCharge model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update AdditionalCharge set ");

            strSql.Append(" [BillDate] = @BillDate , ");
            strSql.Append(" [BillAmount] = @BillAmount , ");
            strSql.Append(" [AddWho] = @AddWho , ");
            strSql.Append(" [CustomerCode] = @CustomerCode , ");
            strSql.Append(" [OrderNumber] = @OrderNumber , ");
            strSql.Append(" [RefOrderNumber] = @RefOrderNumber , ");
            strSql.Append(" [Amount] = @Amount , ");
            strSql.Append(" [Notes] = @Notes , ");
            strSql.Append(" [AddTime] = @AddTime , ");
            strSql.Append(" [Status] = @Status , ");
            strSql.Append(" [BillWho] = @BillWho  ");
            strSql.Append(" where ID=@ID ");

            OleDbParameter[] parameters = {
			            new OleDbParameter("@ID", OleDbType.Integer,4) ,            
                        new OleDbParameter("@BillDate", OleDbType.Date) ,            
                        new OleDbParameter("@BillAmount", OleDbType.Date) ,            
                        new OleDbParameter("@AddWho", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@CustomerCode", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@OrderNumber", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@RefOrderNumber", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@Amount", OleDbType.Double) ,            
                        new OleDbParameter("@Notes", OleDbType.VarChar,255) ,            
                        new OleDbParameter("@AddTime", OleDbType.Date) ,            
                        new OleDbParameter("@Status", OleDbType.Integer,4) ,            
                        new OleDbParameter("@BillWho", OleDbType.VarChar,255)             
              
            };

            parameters[11].Value = model.ID;
            parameters[12].Value = model.BillDate;
            parameters[13].Value = model.BillAmount;
            parameters[14].Value = model.AddWho;
            parameters[15].Value = model.CustomerCode;
            parameters[16].Value = model.OrderNumber;
            parameters[17].Value = model.RefOrderNumber;
            parameters[18].Value = model.Amount;
            parameters[19].Value = model.Notes;
            parameters[20].Value = model.AddTime;
            parameters[21].Value = model.Status;
            parameters[22].Value = model.BillWho;
            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from AdditionalCharge ");
            strSql.Append(" where ID=@ID");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)
};
            parameters[0].Value = ID;


            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from AdditionalCharge ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public KF.DHLModel.AdditionalCharge GetModel(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID], [BillDate], [BillAmount], [AddWho], [CustomerCode], [OrderNumber], [RefOrderNumber], [Amount], [Notes], [AddTime], [Status], [BillWho]  ");
            strSql.Append("  from AdditionalCharge ");
            strSql.Append(" where ID=@ID");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)
};
            parameters[0].Value = ID;


            KF.DHLModel.AdditionalCharge model = new KF.DHLModel.AdditionalCharge();
            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BillDate"].ToString() != "")
                {
                    model.BillDate = DateTime.Parse(ds.Tables[0].Rows[0]["BillDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BillAmount"].ToString() != "")
                {
                    model.BillAmount = DateTime.Parse(ds.Tables[0].Rows[0]["BillAmount"].ToString());
                }
                model.AddWho = ds.Tables[0].Rows[0]["AddWho"].ToString();
                model.CustomerCode = ds.Tables[0].Rows[0]["CustomerCode"].ToString();
                model.OrderNumber = ds.Tables[0].Rows[0]["OrderNumber"].ToString();
                model.RefOrderNumber = ds.Tables[0].Rows[0]["RefOrderNumber"].ToString();
                model.Notes = ds.Tables[0].Rows[0]["Notes"].ToString();
                if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "")
                {
                    model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Status"].ToString() != "")
                {
                    model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                model.BillWho = ds.Tables[0].Rows[0]["BillWho"].ToString();

                return model;
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM AdditionalCharge ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOleDb.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" * ");
            strSql.Append(" FROM AdditionalCharge ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperOleDb.Query(strSql.ToString());
        }



    }
}

